package com.weixin.paleituo.factory;

import android.support.v4.app.Fragment;

import com.weixin.paleituo.fragment.AbolistOrderFragment;
import com.weixin.paleituo.fragment.AllOrderFragment;
import com.weixin.paleituo.fragment.AwaitPayFoOrderFragment;
import com.weixin.paleituo.fragment.AwaitRecevingGoodsOrderFragment;
import com.weixin.paleituo.fragment.CompleteOrderFragment;
import com.weixin.paleituo.util.LogUtils;

import java.util.HashMap;

/**
 * Author yichao
 * Time  2017/11/30 9:36
 * Dest  订单fragment的工厂
 */

public class OrderFragmentFactory {
    public static String TAG = "OrderFragmentFactory";
    private static final int AllOrder_Fragment = 0;
    private static final int AwaitPayFoOrder_Fragment = 1;
    private static final int AwaitRecevingGoodsOrder_Fragment = 2;
    private static final int CompleteOrder_Fragment = 3;
    private static final int AbolistOrder_Fragment = 4;
    private static HashMap<Integer, Fragment> mMap = new HashMap();


    public static Fragment getFragment(int index) {
        Fragment fragment = null;
        if (mMap.containsKey(index)) {
            fragment = mMap.get(index);
            LogUtils.i(TAG, "复用" + index);
        } else {
            switch (index) {
                case AllOrder_Fragment:
                    fragment = new AllOrderFragment();
                    break;
                case AwaitPayFoOrder_Fragment:
                    fragment = new AwaitPayFoOrderFragment();
                    break;
                case AwaitRecevingGoodsOrder_Fragment:
                    fragment = new AwaitRecevingGoodsOrderFragment();
                    break;
                case CompleteOrder_Fragment:
                    fragment = new CompleteOrderFragment();
                    break;
                case AbolistOrder_Fragment:
                    fragment = new AbolistOrderFragment();
                    break;
            }
            LogUtils.i(TAG, "新建" + index);
            mMap.put(index, fragment);
        }
        return fragment;

    }


}
